package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.LedgerMerchantService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.LedgerMerchantDto;
import com.huilian.iotbox.data.dto.LedgerMerchantRecordDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;

@RestController
@RequestMapping("/api/ledgerMerchant")
public class LedgerMerchantController extends UserInfoController{
    @Resource
    private LedgerMerchantService ledgerMerchantService;

    /**
     * 查询场地对应分账信息
     * */
    @GetMapping("/findAreaSubLedgerMerchantByMerchantStoreId")
    public ServerResponse findAreaSubLedgerMerchantByMerchantStoreId(Integer merchantStoreId, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        LedgerMerchantDto ledgerMerchantDto = new LedgerMerchantDto();
        ledgerMerchantDto.setMerchantStoreId(merchantStoreId);
        ledgerMerchantDto.setUserInfo(userInfo);
        return ledgerMerchantService.findAreaSubLedgerMerchantByMerchantStoreId(ledgerMerchantDto);
    }

    /**
     * 停止分账
     * */
    @PostMapping("updateFailureTime")
    public ServerResponse updateFailureTime(HttpServletRequest request, @RequestBody LedgerMerchantDto ledgerMerchantDto) throws ParseException {
        UserInfo userInfo = super.getLoginUserInfo(request);
        ledgerMerchantDto.setUserInfo(userInfo);
        return ledgerMerchantService.updateFailureTime(ledgerMerchantDto);
    }

    /**
     * 查询分账比例记录
     * */
    @PostMapping("/ledgerProportionRecord")
    private ServerResponse findLedgerMerchantRecord(@RequestBody LedgerMerchantDto LedgerMerchantDto, HttpServletRequest request){
        UserInfo userInfo = super.getLoginUserInfo(request);
        LedgerMerchantDto.setUserId(userInfo.getId());
        return ledgerMerchantService.ledgerProportionRecord(LedgerMerchantDto);
    }
}
